import tkinter as tk
from tkinter import filedialog, messagebox
from datetime import datetime
from PIL import Image, ImageTk
from tkcalendar import DateEntry
import json
import os
import re



from .Create import *
def add_task(task_name, priority, due_date, image_path, dialog,columns,frames,DATA_FILE,window):
    try:
        if not task_name or not priority or not due_date:
            raise ValueError("You must enter all fields")
        datetime.strptime(due_date, '%Y-%m-%d')
        create_card(frames["To_Do"], task_name, priority, due_date, image_path,window,columns,frames,DATA_FILE)
        dialog.destroy()
        save_tasks(columns,frames,DATA_FILE)  # 保存任务数据到JSON文件
    except ValueError as ve:
        messagebox.showerror("Error", str(ve))
    except Exception as e:
        messagebox.showerror("Unknown error", str(e))